package com.huangge1199.codewars;

import com.huangge1199.codewars.common.Point;

import java.math.BigDecimal;
import java.util.*;

/**
 * @ClassName Kata
 * @Description TODO
 * @Author huangge1199
 * @Date 2021/10/15 13:53
 **/
public class Kata {

    /**
     * [4kyu]Large Factorials
     */
    public static String Factorial(int n) {
        BigDecimal bigDecimal = new BigDecimal(1);
        for (int i = 1; i <= n; i++) {
            bigDecimal = bigDecimal.multiply(new BigDecimal(i));
        }
        return String.valueOf(bigDecimal);
    }

    /**
     * [3 kyu]Closest pair of points in linearithmic time
     */
    public static List<Point> closestPair(List<Point> points) {
        double min = Integer.MAX_VALUE;
        List<Point> pointList = new ArrayList<>();
        for (int i = 0; i < points.size() - 1; i++) {
            Point point1 = points.get(i);
            for (int j = i + 1; j < points.size(); j++) {
                Point point2 = points.get(j);
                if (point1.equals(point2)) {
                    continue;
                }
                double mul = Math.pow(point1.x - point2.x, 2) + Math.pow(point1.y - point2.y, 2);
                if (mul < min) {
                    pointList = Arrays.asList(point1, point2);
                    min = mul;
                }
            }
        }
        return pointList;
    }
}
